package com.javaee.spring.chineseIdol;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@Configuration
public class ChineseIdolConfig {
	@Bean
	public Performer li(){
		return new Juggler();
	}
	@Bean
	public Performer xiaoli(){
		return new Juggler(10);
	}
	@Bean
	public Instrument instrument(){
		return new Piano();
	}

	@Bean
	public Performer xiaowang(){
		Instrumentalist xiaowang = new Instrumentalist();
		xiaowang.setSong("额呵呵");
		xiaowang.setInstrument(instrument());
		
		return xiaowang;
	}
	public static void main(String[] args) {
		ConfigurableApplicationContext ctx =
			      new ClassPathXmlApplicationContext("com/javaee/spring/chineseIdol/chinese-idol-auto.xml");
		ChineseIdolConfig config = (ChineseIdolConfig)ctx.getBean("config");
		try {
			config.li().performer();
			config.xiaoli().performer();
			config.xiaowang().performer();
		} catch (PerformanceException e) {
			
			e.printStackTrace();
		}
		ctx.close();
	}

}
